package com.ssy.jt808.gateway.sdk.terminal.converter.location.addition;

import com.ssy.jt808.gateway.sdk.terminal.pojo.info.VehicleSignalInfo;
import com.ssy.jt808.gateway.sdk.terminal.utils.BitUtil;

/**
 * @author wangzezhou
 */
public class VehicleSignalInfoConverter{

  /** 近光灯 */
  private static int DIPPED_HEADLIGHT = 0x01;
  /** 远光灯 */
  private static int HIGH_BEAM        = 0x01<<1;
  /** 右转向灯 */
  private static int RIGHT_TURN       = 0x01<<2;
  /** 左转向灯 */
  private static int LEFT_TURN        = 0x01<<3;
  /** 刹车 */
  private static int BRAKE            = 0x01<<4;
  /** 倒档 */
  private static int REVERSE_GEAR     = 0x03<<5;
  /** 雾灯 */
  private static int FOG_LAMP         = 0x01<<6;
  /** 示廓灯 */
  private static int POSITION_LAMP    = 0x01<<7;
  /** 喇叭 */
  private static int HORN             = 0x01<<8;
  /** 空调 */
  private static int AIR_CONDITIONER  = 0x01<<9;
  /** 空档 */
  private static int NEUTRAL          = 0x01<<10;
  /** 缓速器 */
  private static int RETARDATION      = 0x01<<11;
  /** ABS */
  private static int ABS              = 0x01<<12;
  /** 加热器 */
  private static int HEATER           = 0x01<<13;
  /** 车辆离合 */
  private static int CLUTCH           = 0x01<<14;

  public static VehicleSignalInfo convertVehicleSignalInfo( int signal ){

    VehicleSignalInfo info = new VehicleSignalInfo();
    if( signal == 0 ){
      return info;
    }

    info.setDippedHeadlight(BitUtil.existFlag(signal, DIPPED_HEADLIGHT));
    info.setHighBeam(BitUtil.existFlag(signal, HIGH_BEAM));
    info.setRightTurn(BitUtil.existFlag(signal, RIGHT_TURN));
    info.setLeftTurn(BitUtil.existFlag(signal, LEFT_TURN));
    info.setBrake(BitUtil.existFlag(signal, BRAKE));
    info.setReverseGear(BitUtil.existFlag(signal, REVERSE_GEAR));
    info.setFogLamp(BitUtil.existFlag(signal, FOG_LAMP));
    info.setPositionLamp(BitUtil.existFlag(signal, POSITION_LAMP));
    info.setHorn(BitUtil.existFlag(signal, HORN));
    info.setAirConditioner(BitUtil.existFlag(signal, AIR_CONDITIONER));
    info.setNeutral(BitUtil.existFlag(signal, NEUTRAL));
    info.setRetardation(BitUtil.existFlag(signal, RETARDATION));
    info.setAbs(BitUtil.existFlag(signal, ABS));
    info.setHeater(BitUtil.existFlag(signal, HEATER));
    info.setClutch(BitUtil.existFlag(signal, CLUTCH));

    return info;
  }
}
